﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cn.Edwon.Web.Session;
using Cn.Cellula.Model.Security;

namespace Cn.Cellula.Biz {
    #region power state definition

    public enum PowerAct { 
        Visiable = 90,
        Editable = 80
    }
    
    /// <summary>
    /// Power state
    /// </summary>
    public class PowerState {
        public PowerState() {
            _Read = false;
            _Write = false;
        }
        private Boolean _Read;
        public Boolean Visible{
            set { _Read = value; }
            get { return _Read; }
        }
        private Boolean _Write;
        public Boolean Editable {
            set { _Write = value; }
            get { return _Write; }
        }
    }
    #endregion

    public class PowerBiz {
        /// <summary>
        /// 编辑用户资料时的权限
        /// </summary>
        /// <param name="rActor"></param>
        /// <param name="rUser"></param>
        /// <returns></returns>
        public static PowerState UserEdit(ISessActor rActor,VSysUserEO rUser) {
            PowerState ps = new PowerState();
            if (rActor == null || rUser==null) return ps;
            // actor的等级要高于user的等级
            // 是同一个人
            // 编辑对象不是ADMIN
            ps.Visible = ((rActor.Power.RoleLevel > rUser.RoleLevel || rActor.ID == rUser.UserKey)
                && rUser.UserKey.ToLower() != BizConst.Admin.KEY.ToLower());
            // 1,actor的等级要高于user的等级
            // 2,是同一个人
            ps.Editable = ((rActor.Power.RoleLevel > rUser.RoleLevel || rActor.ID == rUser.UserKey));

            return ps;
        }

        
    }
}
